<template>
    <!-- 页面头部 -->
    <HomePageHead></HomePageHead>
    <!-- 导航栏 -->
    <HomePageNavigation></HomePageNavigation>
    <!-- 列表页广告一 -->
    <HomeTopTen :imgurl="adImg1" v-if="adImg1"></HomeTopTen>
    <!-- 资讯列表 -->
    <Detail_news v-if="routeType == 1"></Detail_news>
    <!-- 商品详情 -->
    <Detail_goods v-if="routeType == 2"></Detail_goods>
    <!-- 列表页广告一 -->
    <HomeTopTen :imgurl="adImg2" v-if="adImg2"></HomeTopTen>
    <!-- 页面底部 -->
    <HomeFoot1></HomeFoot1>
</template>

<script setup>
//1.页面依赖 start ---------------------------------------->
import { onMounted } from 'vue'
import Detail_goods from '~/components/goods/detail_sec.vue';
import Detail_news from '~/components/news/detail_sec.vue';
//1.页面依赖 end ---------------------------------------->

//2.页面路径 start ---------------------------------------->
const route = useRoute();
const articleId = parseInt(route.params.id);
const targetSegment = getRoutePath(2);

let routeType;
//通过导航路径反向查询导航id
const getRouteType = await requestDataPromise('/web/getWebsiteRoute', {
    method: 'GET',
    query: {
        'pinyin': targetSegment,
    },
});
// console.log('targetSegment', getRouteType);

if (getRouteType.code == 200) {
    routeType = getRouteType.data.type
} else {
    console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
    console.log("错误位置：通过url路径查询导航池id")
    console.log("后端错误反馈：", getRouteType.message)
    console.log("SSR waring ---------- SSR waring ---------- SSR waring ---------->")
}
//2.页面路径 end ---------------------------------------->


//5.广告 start ---------------------------------------->
let adImg1 = ref([]);
let adImg2 = ref([]);
onMounted(async () => {
    const { $webUrl, $CwebUrl } = useNuxtApp();
    //广告1
    let url = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snscw_detail_0001`
    const responseAd1 = await fetch(url, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd1 = await responseAd1.json();
    adImg1.value = resultAd1.data[0];
    //广告2
    let url2 = `${$webUrl}/web/getWebsiteAdvertisement?ad_tag=snscw_detail_0002`
    const responseAd2 = await fetch(url2, {
        headers: {
            'Content-Type': 'application/json',
            'Userurl': $CwebUrl,
            'Origin': $CwebUrl
        }
    });
    const resultAd2 = await responseAd2.json();
    adImg2.value = resultAd2.data[0];
})
//5.广告 end ---------------------------------------->

//6.设置seo信息 start---------------------------------------->
const setData = await requestDataPromise('/web/selectWebsiteArticleInfo', {
    method: 'GET',
    query: {
        'articleid': articleId
    },
});
if (setData.code == 200) {
    let seoTitle = setData.data.title;
    let seoDescription = setData.data.introduce;
    let seoKeywords = setData.data.keyword;
    let seoSuffix = setData.data.suffix;
    let seoName = setData.data.website_name;

    useSeoMeta({
        title: seoTitle + "_" + seoName + "_" + seoSuffix,
        meta: [
            { name: 'description', content: seoDescription + "_" + seoName + "_" + seoSuffix, tagPriority: 10 },
            { name: 'keywords', content: seoKeywords + "_" + seoName + "_" + seoSuffix, tagPriority: 10 }
        ]
    });
} else {
    console.log("获取广告数据失败！", setData.message)
}
//6.设置seo信息 end---------------------------------------->

</script>

<style lang="less" scoped>
@import url('@/assets/css/detail.less');
</style>